<!--
 * @Author: 凌宇king
 * @Date: 2022-09-24 11:27:43
 * @LastEditTime: 2022-09-27 08:42:07
-->
<template>
    <div>
        <el-container class="body">
            <el-header>
                <div class="headerConfig">
                    <div class="headerLeft">校园帮忙管理后台</div>
                    <div class="headerRight">
                        <p>hello：{{ getAdmin }}</p>
                        <el-button @click="logout" type="danger" size="mini" plain>退出</el-button>
                    </div>
                </div>
            </el-header>
            <el-container>
                <el-aside width="250px" style="background-color: rgb(238, 241, 246)">
                    <el-menu @select="selectMenu" :default-active="menu" class="el-menu-vertical-demo"
                        background-color="#D9E5FD">
                        <el-submenu index="admin">
                            <template slot="title">
                                <i class="el-icon-menu"></i>
                                <span slot="title">管理员菜单</span>
                            </template>
                            <el-menu-item-group>
                                <el-menu-item index="admin">
                                    <i class="el-icon-s-custom"></i>
                                    <span slot="title">管理员管理</span>
                                </el-menu-item>
                                <el-menu-item index="order">
                                    <i class="el-icon-document"></i> <span slot="title">订单管理</span>
                                </el-menu-item>
                                <el-menu-item index="total">
                                    <i class="el-icon-setting"></i> <span slot="title">数据统计</span>
                                </el-menu-item>
                            </el-menu-item-group>
                        </el-submenu>
                    </el-menu>
                </el-aside>
                <el-container>
                    <el-main>
                        <router-view></router-view>
                    </el-main>
                    <el-footer>版本V1.0</el-footer>
                </el-container>
            </el-container>
        </el-container>
    </div>
</template>

<script>
export default {
    data() {
        return {
            menu: 'order'
        }
    },
    mounted() { this.menu = this.$route.name },
    computed: {
        getAdmin() {
            const admin = localStorage.getItem('admin')
            if (admin) {
                const { nickName } = JSON.parse(localStorage.getItem('admin'))
                if (nickName) {
                    return nickName
                } else { this.$router.push({ name: 'login' }) }
            } else {
                this.$router.push({ name: 'login' })
            }
        }
    },
    methods: {
        logout() {
            this.$confirm('确认要退出登录吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                center: true
            }).then(() => {
                this.$message({
                    type: 'success',
                    message: '退出登录成功!'
                })
                localStorage.removeItem('admin')
                this.$router.push({ name: 'login' })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消退出登录'
                });
            });
        },
        selectMenu(key) {
            this.$router.push('/' + key + `?${Math.random() * 1000 + 10}`)
        }
    }
}
</script>

<style lang="scss" scoped>
//修改.el-aside如下
.el-aside {
    background-color: #fff;
    color: #333;
    text-align: center;
    border-right: 1px solid #B3C0D1;
}

//增加.el-menu .el-menu{ border:none }
.el-header,
.el-footer {
    background-color: #B3C0D1;
    color: #333;
    text-align: center;
    line-height: 60px;
}

.el-aside {
    background-color: #D3DCE6;
    color: #333;
    text-align: center;
    line-height: 200px;
}

.el-main {
    background-color: #E9EEF3;
    color: #333;
    text-align: center;
}

.body {
    height: 100vh;

    .el-header {
        background: linear-gradient(to right, rgb(107, 151, 247), rgb(255, 255, 255));
        line-height: 40px;

        .headerConfig {
            display: flex;
            align-items: center;
            justify-content: space-between;

            .headerLeft {
                color: #fff;
                font-size: 20px;
                font-weight: bold;
            }

            .headerRight {
                display: flex;
                align-items: center;

                p {
                    margin-right: 20px;
                }

                .el-button {
                    height: 40px;
                }
            }
        }
    }
}

.el-footer {
    background-color: #B3C0D1;
    color: #333;
    text-align: center;
    line-height: 60px;
}



.el-main {
    background-color: #E9EEF3;
    color: #333;
    text-align: center;
}
</style>